<template>
    <div id="reservation_record">
        <header>
            <i @click="goBack()"></i>
            <div>预约记录</div>
            <span @click='addNewAppointment'>新建</span>
        </header>
        <div class="swipe">
            <Loadmore
                :bottom-method="loadBottom"
                :bottom-all-loaded="allLoaded"
                ref="loadmore"
                :autoFill="false"
            >
            <ul class="list">
                <div class='mc' v-if="list.length<1">
                    <img src="../../../image/no_record@2x.png" width='74' alt="">
                    <p>目前还没有任何预约记录!</p>
                </div>
                <li v-for="(item,index) in list" :key='index'>
                    <!-- <router-link :to='{name:"reservation_details",query: {id: item.id,pid:pid}}'> -->
                        <a @click="toNext(item.id)">
                        <ul>
                            <li>
                                <span class='bold'>
                                    {{item.time}}    {{item.time | getDay}} 
                                </span>
                            </li>
                            <!-- <li class='hospital'>
                                <div>
                                    {{item.clinic}}
                                </div>
                            </li> -->

                            <li class='doctor'>
                                {{item.project}}
                            </li>
                            <li class='remarks'>
                                {{item.remarks}}
                            </li>
                        </ul>
                    </a>
                    <!-- </router-link> -->
                </li>
            </ul>
            </Loadmore>
        </div>
    </div>
</template>
<script>
    import {Loadmore} from 'mint-ui';
    export default {
        data() {
            return {
                list: [],
                type:'',//当前身份
                doctorid: '', //医生id
                pid: '',  //患者id
                sentPage:{
                    page: 1,
                    rows:"10"
                },//接口入参
                totalNum: 0, //总数据条数
                allLoaded: false,					//分页数据是否已经加载完毕
            }
        },
        components: {
            Loadmore,
        },
        filters: {
            getDay: function (val) {  //返回星期几
                var d=new Date(val);
                var weekday=new Array(7)
                weekday[0]="星期天"
                weekday[1]="星期一"
                weekday[2]="星期二"
                weekday[3]="星期三"
                weekday[4]="星期四"
                weekday[5]="星期五"
                weekday[6]="星期六"
                return weekday[d.getDay()]
            }
        },
        methods: {
            goBack() {
                // this.$router.back();
                // this.$router.push({name:'appointmentTime',query: {user:'doctor'}});  
                if(this.type=='"clinic"'){
                    this.$router.push({name:'clinicDetails',query: {pid:this.pid}});  
                }else{
                    this.$router.push({name:'patientDetails',query: {pid:this.pid}});  
                }
                

                         
            },
            // 获取预约患者列表
            getList(params) {
                this.doctorid = localStorage.getItem("loginMobile");
                this.pid = this.$route.query.pid;
                this.$api.post(this.$api.baseURLSchool,"selecttype_view/appointment/0?pid="+this.pid+"&doctorid="+this.doctorid,params,r => {
                    this.totalNum = r.data.records; //总数据
					if(this.sentPage.page==1) {
						this.list = r.data.rows;
					}else {
						this.list = this.list.concat(r.data.rows);
					}
					if(r.data.rows.length == 0&&this.sentPage.page>1) {
						this.$utils._toast("暂无更多数据");
                    }
                    if(this.totalNum == this.list.length) {
                        this.allLoaded = true;
                    }
                    
                },err => {  
                    console.log(err);
                })
            },
            //新建预约
            addNewAppointment() {
                this.$router.push({name:'addNewAppointment',
                    query: {from: "reservation_record",pid: this.pid,status:'add'}});
                // if(localStorage.getItem('name')=='"clinic"'){
                //     this.$router.push({name:'addNewAppointment1',
                //     query: {from: "reservation_record",pid: this.pid}});
                // }else if(localStorage.getItem('name')=='"doctor"'){
                   
                // }
            },
            //上拉加载下一页
            loadBottom() {
                (this.sentPage.page)++;
		        setTimeout(() => {
		        	this.getList(this.sentPage);
		        }, 20);
		        if(this.totalNum == this.list.length) {
					this.allLoaded = true;
		        }
				this.$refs.loadmore.onBottomLoaded();
            },


            toNext(id){
                if(this.$route.query.name=='order'){
                    this.$router.push({name:'clinicDetail',query:{
                    pid: this.pid,blid:id,user:'doctor',id:this.doctorid
                }});
                }else{
                    this.$router.push({name:'reservation_details',query:{
                    pid: this.pid,id:id
                }});
                }
                
            }

        },
        created() {
            this.type=localStorage.getItem('type')
            this.getList(this.sentPage);
        },
        mounted() {
        }
    }
</script>
<style lang="scss" scoped>
    .mc {
        padding-top: 115px;
        img {
            display: block;
            margin: 0 auto;
        }
        p {
            padding-top: 10px;
            text-align: center;
            font-size: 17px;
            color: rgba(51,51,51,1);
        }
    }
    footer{
        background: #fff;
    border-top: 10px solid #f6f6f6;
    height: 50px;
    }
</style>